package com.wwp.tbshop.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.wwp.tbshop.R;
import com.wwp.tbshop.event.SaleNewsCartEventbus;
import com.wwp.tbshop.model.adapter.BrandRecommendRVAdapter;
import com.wwp.tbshop.model.bean.BrandRecommendBean;
import com.wwp.tbshop.presenter.BrandRecommendPresenter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by ${wenping} on 6/17/2017.
 */

public class BrandRecommendActivity extends BaseActivity {

    @Bind(R.id.brand_recommend_recyclerview)
    RecyclerView mBrandRecommendRecyclerview;
    @Bind(R.id.brand_recommend_back)
    ImageView mBrandRecommendBack;
    @Bind(R.id.brand_recommend_cart)
    ImageView mBrandRecommendCart;
    private BrandRecommendPresenter mBrandRecommendPresenter;
    private BrandRecommendRVAdapter mBrandRecommendRVAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_brand_recommend;
    }

    @Override
    protected void init() {
        super.init();
        mBrandRecommendPresenter = new BrandRecommendPresenter(this);
        mBrandRecommendPresenter.loadBrandRecommend();

        mBrandRecommendRecyclerview.setLayoutManager(new GridLayoutManager(this, 3));
        mBrandRecommendRVAdapter = new BrandRecommendRVAdapter(this);
        mBrandRecommendRecyclerview.setAdapter(mBrandRecommendRVAdapter);
    }

    List<BrandRecommendBean.BrandBean> totalValue = new ArrayList<>();
    private static final String TAG = "BrandRecommendActivity";

    public void onBrandRecommendSuccess(List<BrandRecommendBean.BrandBean> list) {
        for (int i = 0; i < list.size(); i++) {
            BrandRecommendBean.BrandBean brandBean = list.get(i);
            List<BrandRecommendBean.BrandBean.ValueBean> valueBeanList = brandBean.getValue();
            mBrandRecommendRVAdapter.setBrandBeanList(valueBeanList);
            Log.e(TAG, "onBrandRecommendSuccess " + valueBeanList.size());
        }
    }

    @OnClick({R.id.brand_recommend_back, R.id.brand_recommend_cart})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.brand_recommend_back:
                finish();
                break;
            case R.id.brand_recommend_cart:
                //跳转到购物车;有问题呢;
                SaleNewsCartEventbus eventbus = new SaleNewsCartEventbus();
                eventbus.SalenewsToMain(this);
                EventBus.getDefault().post(eventbus);
                break;
        }
    }
}
